import FindPathMgr from "./FindPathMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CupHolderItemCtrl extends cc.Component {
    @property(cc.Node)
    elementNode: cc.Node = null;

    @property(cc.Node)
    seqNode: cc.Node = null;

    @property(cc.SpriteFrame)
    changeSp: cc.SpriteFrame = null;

    row: number = null;
    col: number = null;
    isChose: boolean = false;

    start() { }

    initData(data: { row: number, col: number }) {
        if (data) {
            const { row, col } = data;
            this.row = row;
            this.col = col;
            this.seqNode.active = false;
        }
    }

    setChoseSp(chose: boolean) {
        if (!this.isChose || !chose) {
            this.isChose = chose;
            if (chose) {
                this.elementNode.getComponent(cc.Sprite).spriteFrame = this.changeSp;
                FindPathMgr.addPosToPath({
                    row: this.row,
                    col: this.col,
                    isHavePalce: true,
                });
            } else {
                this.elementNode.getComponent(cc.Sprite).spriteFrame = null;
                FindPathMgr.deletePos({
                    row: this.row,
                    col: this.col,
                    isHavePalce: false,
                });
            }
        }
    }
}

